<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>ES6的面向对象编程</title>
</head>
<body>
<script>
//定义类Point
class Point{
    constructor(x, y){
        this.x = x;
        this.y = y;
    }  // 不要加逗号
    toSting(){
        return `(${this.x}, ${this.y})`;
    }
}
// 实例化，得到一个对象
var p = new Point(10, 20);
console.log(p.x)
console.log(p.toSting());
class ColorPoint extends Point{
    constructor(x, y, color){
        super(x, y);  // 调用父类的constructor(x, y)
        this.color = color;
    }  // 不要加逗号
    showColor(){
        console.log('My color is ' + this.color);
    }
}

var cp = new ColorPoint(10, 20, "red");
console.log(cp.x);
console.log(cp.toSting());
cp.showColor()

</script>	
</body>
</html>